package com.tencent.sr.iris.activity.service.convert;

import cn.hutool.core.date.DateUtil;
import com.tencent.sr.iris.activity.interfaces.response.activity.BatchDataResponse;
import com.tencent.sr.iris.activity.repository.entity.TIrisUserTaskBatchDataDO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;

import java.util.Date;
import java.util.Objects;
import java.util.Optional;

/**
 * @author nixiaolin
 * @date 2022/7/22 10:56
 */
@Mapper(componentModel = "spring", imports = {Date.class, Objects.class, Optional.class, DateUtil.class})
public interface UserTaskBatchDataConvert {

    @Mapping(target = "traineeTime", expression = "java(Optional.ofNullable(batchDataDO.getTraineeTime()).map(Date::getTime).orElse(null))")
    @Mapping(target = "awardSendTime", expression = "java(Optional.ofNullable(batchDataDO.getAwardSendTime()).map(Date::getTime).orElse(null))")
    @Mapping(target = "currentTaskStartTime", expression = "java(Optional.ofNullable(batchDataDO.getCurrentTaskStartTime()).map(Date::getTime).orElse(null))")
    @Mapping(target = "currentTaskEndTime", expression = "java(Optional.ofNullable(batchDataDO.getCurrentTaskEndTime()).map(Date::getTime).orElse(null))")
    @Mapping(target = "awardRecordTime", expression = "java(Optional.ofNullable(batchDataDO.getAwardRecordTime()).map(Date::getTime).orElse(null))")
    @Mapping(target = "consumeTime", expression = "java(Optional.ofNullable(batchDataDO.getConsumeTime()).map(Date::getTime).orElse(null))")
    @Mapping(target = "specialInviteTime", expression = "java(Optional.ofNullable(batchDataDO.getSpecialInviteTime()).map(Date::getTime).orElse(null))")
    @Mapping(target = "superiorSpecialInviteTime", expression = "java(Optional.ofNullable(batchDataDO.getSuperiorSpecialInviteTime()).map(Date::getTime).orElse(null))")
    @Mapping(target = "orderFinishTime", expression = "java(Optional.ofNullable(batchDataDO.getOrderFinishTime()).map(Date::getTime).orElse(null))")
    BatchDataResponse buildFromBatchDataDO(TIrisUserTaskBatchDataDO batchDataDO);

}
